/* *****************************************************************************************************
 * Copyright 2009. Dbwebx Group
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 * *****************************************************************************************************
 */

package org.dbwebx.webapp;

import java.util.List;

import org.dbwebx.domain.Bundle;
import org.dbwebx.domain.DbUnit;
import org.dbwebx.domain.SourceNode;

import org.dbwebx.service.dao.BundleService;
import org.dbwebx.service.dao.DbUnitService;
import org.dbwebx.service.dao.SourceNodeService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

/**
 * The simple annotation based controller.
 * 
 * @author Izzet_Mustafayev
 * 
 */
@Controller
public class TestController {
	/**
	 * Injects reference to {@link SourceNodeService} implementation.
	 */
	@Autowired
	private SourceNodeService sourceNodeService;

	@Autowired
	private DbUnitService dbUnitService;

	@Autowired
	private BundleService bundleService;

	/**
	 * Home page.
	 */
	@RequestMapping("/home")
	public void home() {
		SourceNode project;
		project = new SourceNode();
		project.setName("My First project.");
		sourceNodeService.persist(project);
		List<Bundle> bundles = bundleService.list();
		if (!bundles.isEmpty()) {
			DbUnit dbUnit = new DbUnit();
			dbUnit.setBundle(bundles.get(1));
			dbUnit.setData("Some SQL data.");
			dbUnit.setName("sample dbunit.");
			dbUnit = dbUnitService.persist(dbUnit);
			if (null != dbUnit) {
				
			}
		}
	}
}
